package com.yh.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.pool.vendor.SybaseExceptionSorter;
import com.alibaba.druid.sql.PagerUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yh.bean.Dept;
import com.yh.bean.PersonApply;
import com.yh.dao.PersonApplyDao;
import com.yh.service.PersonApplyService;

@Service
@Transactional
public class PersonApplyImp  implements PersonApplyService{

	//注入代理dao
	@Autowired
	private PersonApplyDao  apply;

	@Override
	public int setPersonApply(PersonApply pa) {
		//如果申请天数pa_day为其他，则需要给其赋予用户自定义值
		if(pa.getPa_day().equals("其他")){
		     pa.setPa_day(pa.getDays());
	  }
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //申请的时间
		pa.setPa_date(df.format(new Date()));
		pa.setPa_status("待审核");

		return apply.insertApply(pa);
	}

	@Override
	public Map QueryAllApply(int curr) {
	Page<PersonApply> page=PageHelper.startPage(curr,2);
	 List<PersonApply>  lp=apply.QueryAllApply();
	 long count = page.getTotal();
		 Map map=new HashMap();
		 map.put("count", count);
		 map.put("apply", lp);

		return map;
	}
	
	

	@Override
	public Map QueryApply(PersonApply pa,int curr){
		
		Page<PersonApply> page=PageHelper.startPage(curr,2);
		 List<PersonApply>  lp= apply.QueryApply(pa);
		 lp.forEach(ll->System.out.println("lp+++++++++++"+ll.toString()));
	
		 long count = page.getTotal();
		 System.out.println("count++++"+count);
			 Map map=new HashMap();
			 map.put("count", count);
			 map.put("apply", lp);

			return map;
	}

	@Override
	public String deleteApply(PersonApply pa) {
		
		if(apply.deleteApply(pa)!=0){
			
			return "1";
		}
		
		return "0";
	}

	@Override
	public String BossUpdateApply(PersonApply pa) {
		   if(apply.bossUpdateApply(pa)!=0){
			   return "1";
		   }
		return "0" ;
	}

	@Override
	public String personUpdateApply(PersonApply pa) {
		if(apply.personUpdateApply(pa)!=0){
			 return "1";
		}
		
		return "0" ;
	}

	@Override
	public String getBossName(int userid) {
		
		return apply.getBossName(userid);
	}

	@Override
	public String getDeptName(int userid) {
		return apply.getDeptName(userid);
	}

	
	//批量删除
	@Override
	public String deleteArrayApply(int[] array) {
	
		 if(apply.deleteArrayApply(array)!=0){
			 return "1";
		 }
		
		
		return "0" ;
	}

	
	
	@Override
	public List<Dept> queryAllDept() {
		System.out.println("查询部门");
		
		return apply.queryAllDept();
		
	} 
	
	
	
	

}
